<%@ page import="org.apache.shiro.SecurityUtils" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	//如果用户是登录状态立即跳转首页
	if (SecurityUtils.getSubject().isAuthenticated()) {
		response.sendRedirect("/index");
	}
%>
<!DOCTYPE html>
<html>
	<head>
		<base href="<%=basePath%>">
		<meta charset="utf-8">
		<title>Login Page</title>
		<!-- 样 式 文 件 -->
		<link rel="stylesheet" href="/component/pear/css/pear.css" />
		<link rel="stylesheet" href="/admin/css/other/login.css" />
	</head>
    <!-- 代 码 结 构 -->
	<body background="/admin/images/background.svg" style="background-size: cover;">
		<form class="layui-form" action="user/login" method="post">
			<div class="layui-form-item">
				<img class="logo" src="/admin/images/logo.png" />
				<div class="title">JinFu Admin</div>
				<!--<div class="desc">
					明 湖 区 最 具 影 响 力 的 设 计 规 范 之 一
				</div>-->
			</div>
			<div class="layui-form-item">
				<input placeholder="请输入账号 :" lay-verify="required" hover class="layui-input" name="username"  />
			</div>
			<div class="layui-form-item">
				<input type="password" placeholder="请输入密码 :" lay-verify="required" hover class="layui-input" name="password"  />
			</div>
			<div class="layui-form-item">
				<input placeholder="验证码 : "  hover  lay-verify="required" class="code layui-input layui-input-inline"  name="verifyCode"/>
				<img id="verifyCodeImg" alt="点击更换" src="common/getVerifyCodeImg"
					 title="点击更换" onclick="change()" class="codeImage">
			</div>
			<div class="layui-form-item">
				<input type="checkbox" name="rememberMe" title="记住密码" lay-skin="primary" value="true">
			</div>
			<div class="layui-form-item">
				<button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
					登 入
				</button>
			</div>
		</form>
		<!-- 资 源 引 入 -->
		<script src="/component/layui/layui.js"></script>
		<script src="/component/pear/pear.js"></script>
		<script>
			function change() {
				var verifyCode = document.getElementById("verifyCodeImg");
				verifyCode.src = "common/getVerifyCodeImg?time=" + Math.random(1000);
			}

			layui.use(['form', 'button', 'popup'], function () {
				var form = layui.form;
				var button = layui.button;
				var popup = layui.popup;
				var $ = layui.jquery;

				form.on('submit(login)', function (data) {
					var dom = button.load({
						elem: '.login'
					})
					$.ajax({
						url: 'user/login',
						method: 'post',
						contentType: 'application/x-www-form-urlencoded',
						//data: JSON.stringify(data.field),
						data: data.field,
						success: function (res) {
							dom.stop(function() {
								popup.success("登录成功", function () {
									location.href = "/index"
								});
							});
						},
						error: function (data) {
							dom.stop(function() {
								popup.failure(data.responseJSON.detail);
							});
						}
					});
				});
				return false;
			});
		</script>
	</body>
</html>
